﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HA.MT3DMS.DomainLayer
{
    [Serializable]
    public class MTSpeciesCollecion
    {


        public MTSpeciesCollecion(int rows,int cols,int layers)
        {
            this._species = new List<MTSpecies>();
            this._nRow = rows;
            this._nCol = cols;
            this._nlayer = layers; 
        }


        #region 事件模型
        [field:NonSerialized]
        public event EventHandler SpecifiesChanged;
        #endregion

        int _nRow;

        public int NRow
        {
            get { return _nRow; }
        }

        int _nCol;

        public int NCol
        {
            get { return _nCol; }
        }

        int _nlayer;

        public int Nlayer
        {
            get { return _nlayer; }
        }

        List<MTSpecies> _species;

        public List<MTSpecies> Species
        {
            get { return _species; }

        }


        public int SpeciesCount

        {
            get { return this._species.Count; }
        }



        public int MobileCount
        {
            get {

                int n = 0;

                foreach (MTSpecies item in this._species)
                {
                    if (item.SpeiesMoblie)
                    {
                        n++;
                        
                    }
                    
                }
                
                
                return n; 
            
            
            }
        }


        protected bool IsSpeciesChanged(List<MTSpecies> species)
        {
            if (this._species.Count != species.Count)
            {

                return true;


            }
            else
            {
                for (int i = 0; i < this._species.Count; i++)
                {
                    if (this._species[i].Name != species[i].Name || this._species[i].SpeiesMoblie != species[i].SpeiesMoblie)
                    {
                        return true;
                        
                    }
                    
                }
            }



            return false;

 
        }

        #region 公共函数


        public void ResetSpecies(List<MTSpecies> species)
        {

            //只在真正变化时触发此时间

            if (this.IsSpeciesChanged(species))
            {
                this._species.Clear();
                this._species.AddRange(species);

                if (this.SpecifiesChanged != null)
                {
                    this.SpecifiesChanged(this, new EventArgs());

                }
 
                
            }



        
        }

        public void ResetGrid(int nRow, int nCol, int nLayer)
        {
            this._nRow = nRow;
            this._nCol = nCol;
            this._nlayer = nLayer;


            foreach (MTSpecies item in this._species)
            {
                item.ResetGrid(nRow,nCol,nLayer);
                
            }

        }


        #endregion


    }
}
